% getPatterns
% =============
% Description	: getPatterns get all images from the 
% 		  path directory, then convert all images
%		  to one dimentional vectors in a vector of
%		  images vector

% Parameters
% ----------
% path		: test path directory
% RETURN	: vector of images vector
% example	: getPatterns("images")

function patterns=getPatterns(path)
	[files,err,msg]=readdir(path);

	if (err ==  0)
		p=1;
		
		for f=3:rows(files)
			ip=sprintf("%s/%s", path, files{f});
			if( (index(files{f},".")!=1) && (index(files{f},"t_")!=1) && 
				 (index(files{f},"others")!=1))
				% this is for .svn or hidden files or tested files
				imatrix=imread(ip);
				imatrix = (imatrix*2) - 1;
				patterns{1,p}	=matrixToVect(imatrix);
				patterns{2,p++}	=files{f};
			endif
		endfor
	else
		patterns={};
	endif
endfunction

function v=matrixToVect(matrix)
	v=[];
	for i=1:rows(matrix)
		v=[v,matrix(i,:)];
	endfor
endfunction
